package util;

public class ArrayUtil {

	private static int binarySearch(int[] a, int low, int high, int value)
	{
		if (low == high)
		{
			if (a[low] == value)
				return low;
			else
				return -1;
		}
		
		int mid = (low + high) / 2;
		if (a[mid] == value)
		{
			return mid;
		}
		else if (a[mid] < value)
		{
			return binarySearch(a, mid+1, high, value);
		}
		else
		{
			return binarySearch(a, low, mid-1, value);
		}
	}
	
	// require: a != null and a is sorted
	public static int binarySearch(int[] a, int value)
	{
		if (a.length == 0)
			return -1;
		else
		{
			return binarySearch(a, 0, a.length-1, value);
		}
	}
	
}
